package com.zhkj.txg.module.home.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.txg.R
import com.zhkj.txg.module.home.entity.CategoryTopEntity

class CategoryAllLeftAdapter :
    BaseQuickAdapter<CategoryTopEntity, BaseViewHolder>(R.layout.item_cate_left) {

    init {
        setOnItemClickListener { _, _, position ->
            selectedPosition = position
            notifyDataSetChanged()
            itemClickCallback?.leftClick(data[position])
        }
    }

    var selectedPosition = 0
        private set
    var itemClickCallback: CategoryItemCallback? = null

    override fun convert(helper: BaseViewHolder, item: CategoryTopEntity) {
        helper.itemView.isSelected = selectedPosition == helper.layoutPosition
        helper.setText(R.id.tvCateName, item.name).getView<TextView>(R.id.tvCateName).textSize =
            if (selectedPosition == helper.layoutPosition) 14F else 12F
    }
}

interface CategoryItemCallback {
    fun leftClick(item: CategoryTopEntity)
}